package com.example.capsule_kafka.kafka;

import com.example.capsule_kafka.bean.PositionBean;
import com.example.capsule_kafka.configuration.KafkaConstant;
import com.example.capsule_kafka.impl.PositionServiceImpl;
import com.google.gson.Gson;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Component;

/**
 * @Author: zhuzhiming
 * @Date: 2022/5/18 12:55
 */
@Component
public class PositionTypeConsumer {

    @Autowired
    PositionServiceImpl positionService;


    @KafkaListener(topics = KafkaConstant.POSITION_TOPIC)
    public void positionOperation(String record) {
        PositionBean positionBean = new Gson().fromJson(record, PositionBean.class);
        if (positionBean == null) {
            return;
        }

        if (positionBean.getType() == 0) {
            positionService.uploadPosition(positionBean);
        }

    }

}
